<template>
	<div>
        {{id}}
		<el-form ref="form" :model="form" label-width="100px">
			<el-form-item label="科室名称">
				<el-input v-model="form.name"></el-input>
			</el-form-item>
			<el-form-item label="科室负责人">
				<el-input v-model="form.leader"></el-input>
			</el-form-item>
			<el-form-item label="科室的办公地址">
				<el-input v-model="form.address"></el-input>
			</el-form-item>

		 <el-form-item>
				<el-button type="primary" @click="save">保存部门</el-button>
				<el-button @click="close">取消</el-button>
			</el-form-item>
		</el-form>

	</div>
</template>

<script>
	
	import axios from 'axios';
	
	
	export default {
		name: 'DeptEdit',
		props:[
			'id'
		],
		data() {
			return {
				form: {
					name: '',
					leader: '',
					address: ''
				}

			}
		},
		methods: {
			close(){
				this.$emit('update:visible',false)
			},
			// 修改的时候查询待修改的信息
			queryById(){
				
				this.$http.get('/api/axios_dept', (data) => {
						this.form = data
				}, {
				  _type: "toEdit",
				  id:this.id
				})
				
			},
			save() {
		
				this.form._type="save";

				this.$http.post('api/axios_dept',(success)=>{
					if(success){
						//重新加载数据
						this.$emit('reload')
						this.$emit('update:visible',false)
					}else{ }
				},this.form );
			}
		},
		computed: {

		},
		//在组件呗创建的时候加载数据 初始化
		created() {
			if(this.id){
				//根据主键查询 
				this.queryById()
			}
		}
	}
</script>

<style scoped>


</style>
